from django.shortcuts import render


from common.models import Shop,Category,Product

# 公共信息加载函数
def loadinfo(request):
    lists = Category.objects.filter()
    context = {'categorylist':lists}
    return context

def index(request):
    '''手机端页面'''
    context = loadinfo(request)
    #查询双拼套餐菜品信息
    mod = Product.objects.order_by('-update_at')  
    
    list2 = mod.filter()    

    #封装模板中需要的信息
    context['foodslist'] = list2
    return render(request, "mobile/index.html",context)

def index2(request,id):
    '''手机端页面'''
    context = loadinfo(request)

    #查询双拼套餐菜品信息    
    mod2 = Product.objects.order_by('-update_at')
    mod = Shop.objects.get(id = id)
    
    #list2 = mod.filter()    

    #封装模板中需要的信息
    context['foodslist'] = mod2
    context['shoplist'] = mod.name
    #新店铺
    #context['shopslist'] = shopid
    return render(request, "mobile/index.html",context)

def member(request):
    '''手机端用户基本信息页面'''
    return render(request, "mobile/member.html")

def memberorder(request):
    '''手机端用户基本信息页面'''
    return render(request, "mobile/member-order.html")

def order(request):
    '''手机端用户订餐页面'''
    return render(request, "mobile/order.html")

def shop(request):
    '''手机端店铺列表页面'''
    context = loadinfo(request)
    #查询店铺信息
    mod = Shop.objects    
    
    list2 = mod.filter()
    

    #封装模板中需要的信息
    context['shopslist'] = list2
    
    return render(request, "mobile/shop.html",context)

def register(request):
    '''手机端店铺注册页面'''
    return render(request, "mobile/register.html")
